﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using DAO;

namespace BUS
{
    public class PhongBUS
    {
        public static List<PhongDTO> layDSPhong()
        {
            return PhongDAO.LayDSPhong();
        }

        public static List<PhongDTO> layDSPhongTheoLoaiPhong(string loaiPhong)
        {
            return PhongDAO.LayDSPhongTheoLoaiPhong(loaiPhong);
        }

        public static bool themPhong(string tenPhong, long maLoaiPhong, long tinhTrang, string ghiChu)
        {
            return PhongDAO.ThemPhong(tenPhong, maLoaiPhong, tinhTrang, ghiChu);
        }

        public static void xoaPhong(long maPhong)
        {
            PhongDAO.XoaPhong(maPhong);
        }

        public static void updatePhong(long maPhong, string tenPhong, long maLoaiPhong, long tinhTrang, string ghiChu)
        {
            PhongDAO.UpdatePhong(maPhong, tenPhong, maLoaiPhong, tinhTrang, ghiChu);
        }
        public static List<PhongDTO> layDSPhongTheoMaKH(string maKH)
        {
            return PhongDAO.LayDSPhongTheoMaKH(maKH);
        }
        public static string LayNgayBatDauThue(string maKH, string maphong)
        {
            return DAO.PhongDAO.layNgayBDThue(maKH, maphong);
        }
        public static int laySoNgayThue(string maKH, string maphong)
        {
            string ngaybd = DAO.PhongDAO.layNgayBDThue(maKH, maphong);
            DateTime ngaybdthue = DateTime.Parse(ngaybd);
            TimeSpan c = DateTime.Now.Subtract(ngaybdthue);
            double ngaythue = c.TotalDays;
            int ngayThue = Convert.ToInt32(ngaythue);
            return ngayThue;

        }
        public static bool KiemTraKhachNcNgoai(List<KhachHangDTO> ds)
        {
            for (int i = 0; i < ds.Count; i++)
            {
                if (ds[i].LoaiKhach.MaLoaiKhach == 0)
                {
                    return true;
                }
            }
            return false;
        }
        public static double TinhTien(string maKH, string maphong, int ngaythue)
        {
            List<KhachHangDTO> dsKH = DAO.KhachHangDAO.LaydsKHTheoMaPhongVaMaKH(maKH, maphong);
            double ketqua;
            PhongDTO tam = DAO.PhongDAO.LayDSPhongTheoMaPhong(maphong);
            if (dsKH.Count <= 2)
                ketqua = tam.DonGia.DonGia;
            else
                ketqua = tam.DonGia.DonGia * 0.25;
            if (KiemTraKhachNcNgoai(dsKH) == true)
                return ketqua * 1.5 * ngaythue;
            else
                return ketqua * ngaythue;
        }
    }
}